#################################################################################
#
# Makefile
#
# Makefile for the OpenH323 wrapper Library
#
# Copyright (c) 2002-2005 InAccess Networks
# Michalis Manousos <manousos@inaccessnetworks.com>
# Dimitris Economou <decon@inaccessnetworks.com>
#
# This file is part of "H.323 support for ASTERISK"
#
# "H.323 support for ASTERISK" is free software;
# you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation;
# either version 2 of the License, or (at your option) any later version. 
#
# "H.323 support for ASTERISK" is distributed in the hope that it will be 
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. 
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
#
# $Id: Makefile,v 1.2 2010/05/04 09:02:57 mmanousos Exp $
#
#################################################################################

.EXPORT_ALL_VARIABLES:

.PHONY: .pwlib_version .openh323_version

OPENH323USERFLAGS =
STDCCFLAGS := -fPIC

ifdef	NOVIDEO
OPENH323USERFLAGS += NOVIDEO=1
STDCCFLAGS += -DNO_H323_VIDEO
endif
ifdef	NOAUDIOCODECS
OPENH323USERFLAGS += NOAUDIOCODECS=1
STDCCFLAGS += -DNO_H323_AUDIO_CODECS
endif
ifdef	NOSPEEX
OPENH323USERFLAGS += NO_SPEEX=1
STDCCFLAGS += -DNO_SPEEX
endif
ifdef	NOTRACE
OPENH323USERFLAGS += NOTRACE=1
STDCCFLAGS += -DPASN_NOPRINTON -DPASN_LEANANDMEAN
endif
ifdef	NO_IPv6
OPENH323USERFLAGS += NO_IPv6=1
else
STDCCFLAGS += -DP_HAS_IPV6
endif
ifdef	P_PTHREADS
OPENH323USERFLAGS += P_PTHREADS=1
endif
ifdef	OH323_SUPPRESS_H235
STDCCFLAGS  += -DOH323_SUPPRESS_H235
endif
OPENH323FLAGS := $(shell make $(OPENH323USERFLAGS) -f openh323flags.mak \
		--no-print-directory -s \
		PWLIBDIR=$(PWLIBDIR) OPENH323DIR=$(OPENH323DIR) oh323ccflags)
CPPFLAGS += $(OPENH323FLAGS)

ifeq ($(OH323BUILDTYPE),debug)
CPPFLAGS += -g -D_DEBUG -DNDEBUG
endif

ifeq ($(WRAPTRACING),1)
ifeq (,$(WRAPTRACING_LEVEL))
WRAPTRACING_LEVEL=5
endif
CPPFLAGS += -DWRAPTRACING -DWRAPTRACING_LEVEL=$(WRAPTRACING_LEVEL)
endif

PWLIB_VERSION=$(shell if [ -f .pwlib_version ]; then cat .pwlib_version; else echo "UNKNOWN"; fi)
OH323_VERSION=$(shell if [ -f .openh323_version ]; then cat .openh323_version; else echo "UNKNOWN"; fi)
CPPFLAGS += -DPWLIBVERSION=\"$(PWLIB_VERSION)\" \
			-DOPENH323VERSION=\"$(OH323_VERSION)\"
WRAPOBJECTS = wrapper_misc.o asteriskaudio.o wrapconnection.o wrapendpoint.o \
			  wrapper.o wrapcaps.o wrapgkserver.o
WRAPDEPS = $(shell ls *.hxx *.h)


.pwlib_version:
	./check_ver $(PWLIBDIR) pwlib

.openh323_version:
	./check_ver $(OPENH323DIR) openh323

build: .pwlib_version .openh323_version $(WRAPOBJECTS)
	@if [ "$(PWLIB_VERSION)" = "UNKNOWN" ]; then \
		echo "*** Cannot determine the version of PWLIB!"; exit 1; \
	fi
	@if [ "$(OPENH323_VERSION)" = "UNKNOWN" ]; then \
		echo "*** Cannot determine the version of OPENH323!"; exit 1; \
	fi
ifeq ($(OH323STAT),1)
	$(AR) rc liboh323wrap_s.a $(WRAPOBJECTS)
else
	$(CC) -shared -Wl,-soname,liboh323wrap.so -o liboh323wrap.so $(WRAPOBJECTS)
endif

strip:

install:
	if [ ! -d $(DESTDIR)$(OH323WRAPLIBDIR) ]; then \
		$(INSTALL) -d $(DESTDIR)$(OH323WRAPLIBDIR); \
	fi
ifeq ($(OH323STAT),1)
	$(INSTALL) -m 0644 liboh323wrap_s.a $(DESTDIR)$(OH323WRAPLIBDIR)
else
	$(INSTALL) liboh323wrap.so $(DESTDIR)$(OH323WRAPLIBDIR)
	cd $(DESTDIR)$(OH323WRAPLIBDIR); rm -f ./liboh323wrap.so.1; rm -f ./liboh323wrap.so.1.1
	cd $(DESTDIR)$(OH323WRAPLIBDIR); ln -s liboh323wrap.so liboh323wrap.so.1
	cd $(DESTDIR)$(OH323WRAPLIBDIR); ln -s liboh323wrap.so liboh323wrap.so.1.1
endif

clean:
	rm -f $(WRAPOBJECTS) liboh323wrap* .pwlib_version* .openh323_version*

# Make sure that ASTERISK's channel driver will be re-built.
%.o: %.cxx $(WRAPDEPS)
	$(CPP) $(CPPFLAGS) $(STDCCFLAGS) $(OH323WRAPINCLUDE) -c $< -o $@
	$(TOUCH) ../asterisk-driver/chan_oh323.c

#################################################################################
